package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.*;
import com.zzyl.entity.NursingLevel;
import com.zzyl.entity.NursingPlan;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingPlanDetailVo;
import com.zzyl.vo.NursingSearchLevelVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    NursingLevelMapper mapper;

    @Override
    public PageResponse<NursingSearchLevelVo> selectAll(NursingSearchLevelDto dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        Page<NursingSearchLevelVo> page = mapper.selectAll(dto);
        return PageResponse.of(page, NursingSearchLevelVo.class);
    }

    @Override
    public void add(AddNursingLevelDto dto) {
        NursingLevel level = BeanUtil.copyProperties(dto, NursingLevel.class);
        level.setCreateTime(LocalDateTime.now());
        level.setUpdateTime(LocalDateTime.now());
        level.setLplanId(dto.getLplanId());
        mapper.add(dto);
    }

    @Override
    public NursingSearchLevelVo selectById(Long id) {
        NursingSearchLevelVo vo = mapper.selectById(id);
        return vo;
    }

    @Override
    public void update(UpdateNursingLevelDto dto) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtils.copyProperties(dto, nursingLevel);
        nursingLevel.setUpdateTime(LocalDateTime.now());
        nursingLevel.setCreateTime(LocalDateTime.now());
        mapper.update(nursingLevel);
    }

    @Override
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    public void setStatus(long id, Integer status) {
        mapper.updateStatus(id,status);
    }
}